$(function () {
    getNewsSelectData(0, 10);
})

function changeValue() {
    let reg = /^[12]\d|\d$/;
    if (!reg.test($("#pageSize").val())) {
        $("#pageSize").val(10);
    }
}


//$.trim去掉字符串两边的空格
function getNewsSelectData(startNum, pageSize) {
    let data = {
        title: $.trim($("#title").val()),
        content: $.trim($("#content").val()),
        isTop: $("#isTop").val(),
        // status: $("input[name='status']:checked").val()
        status: $("#status").val(),
        pageSize: pageSize,
        startNum: startNum
    };
    $.ajax({
        url: '/backNewsSelectFindAll',
        data: data,
        dataType: 'json',
        type: 'get',
        success: function (data) {
            console.log(data);
            setNewsDataFindAll(data[0].object);
            $("#count").html(data[0].count);
        }
    })

}

function setNewsDataFindAll(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += ' <tr>\n' +
            '        <td>' + data[i].id + '</td>' +
            '        <td>' + data[i].title + '</td>' +
            '        <td>' + data[i].content + '</td>' +
            '        <td>' + (data[i].isTop == 1 ? '置顶' : '不置顶') + '</td>' +
            '        <td>' + (data[i].status == 1 ? '显示' : '不显示') + '</td>' +
            '        <td>' + data[i].author + '</td>' +
            '        <td>' + data[i].createTime + '</td>' +
            '        <td>编辑 删除</td>\n' +
            '    </tr>';
    }
    $("#backNewsSelectData").html(html);
}